<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【请填写功能名称】列表')" />
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <div style="display: flex;">
                                    <span>实验室名称：</span>
                                    <select name="labId" class="form-control m-b" th:with="type=${@lab.getType()}" style="width:220px;height:32px;">
                                        <option value="">全部</option>
                                        <option th:each="lab : ${type}" th:text="${lab.labName}" th:value="${lab.id}"></option>
                                    </select>
                                </div>
                            </li>

                            <li>
                                <div style="display: flex;">
                                    <span>预约时间：</span>
                                    <div class="input-group date">
                                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                        <input name="experimentDate" class="form-control" id="datetimepicker-demo-2" placeholder="yyyy-MM-dd">
                                    </div>
                                </div>
                            </li>
                            <!--<li>
                                <p>实验室id：</p>
                                <input type="text" name="labId"/>
                            </li>
                            <li>
                                <p>资产类别：</p>
                                <select name="propertyType" th:with="type=${@dict.getType('')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <p>购置日期：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginBuyTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endBuyTime]"/>
                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()" ><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()" ><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:labappointment:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <!--<a class="btn btn-warning" onclick="$.table.exportExcel()">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:labappointment:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:labappointment:remove')}]];
        var prefix = ctx + "labappointment";

        $(function() {
            var options = {
                url: prefix + "/list",
                // createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "【实验室预约】",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : '序号',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field : 'labCode',
                    title : '实验室编号'
                },
                {
                    field : 'labName',
                    title : '实验室名称'
                },
                {
                    field : 'labAddress',
                    title : '实验室地址'
                },
                {
                    field : 'appointmentTime',
                    title : '预约日期'
                },
                {
                    field : 'appointmentJei',
                    title : '预约节次'
                },
                {
                    field : 'createTime',
                    title : '提交时间'
                },{
                    field : 'status',
                    title : '预约状态',
                    formatter: function (value, row, index) {
                        if(value=="0"){
                            return value="<a class='btn btn-primary btn-xs'  href=\"javascript:void(0)\"><i class=\"fa\"></i>待审核</a>";
                        }else if(value=="1"){
                            return value="<a class='btn btn-primary btn-xs'  href=\"javascript:void(0)\"><i class=\"fa\"></i>已通過</a>";
                        }else if(value=="2"){
                            return value="<a class='btn btn-primary btn-xs'  href=\"javascript:void(0)\"><i class=\"fa\"></i>被拒绝</a>";
                        }
                    }
                },{
                    field : 'remark',
                    title : '备注',
                    formatter:function (value,row,index) {
                         if(value==null || value==''){
                             return value="无备注";
                         }else{
                             return $.table.tooltip(value);
                         }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    field: 'id',
                    formatter: function(value, row, index) {
                        var actions = [];
                            if(row.status=="1"){
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)"  disabled="disabled" title="已通过预约，不可撤销"><i class="fa fa-edit"></i>撤销预约</a> ');
                            }else{
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="backout(\'' + row.id + '\')"><i class="fa fa-edit"></i>撤销预约</a> ');
                            }
                            /*actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="goOut(\'' + row.id + '\')"><i class="fa fa-remove"></i>通过</a>');

                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="refuse(\'' + value + '\')"><i class="fa fa-remove"></i>拒绝</a>');*/

                        //actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="look(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="refuse(\'' + row.id + '\')"><i class="fa fa-remove"></i>拒绝</a>');
                           actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editAppointment(\'' + row.id + '\')"><i class="fa fa-edit"></i>修改</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function add(id){
            var url = prefix + '/addlist' ;
            $.modal.openTab("实验室预约", url);
            // window.location.href=url;
        }
        function backout(id){
            $.modal.confirm("确认要撤销预约吗?", function() {
                    $.ajax({
                        type: 'get',
                        dataType: 'json',
                        contentType:"application/json;charset=utf-8",
                        url: prefix + "/quitApply",
                        data: {'id':id},
                        cache: false,
                        async: true,
                        success: function (data) {
                            if(data.code==500){
                                $.modal.msgError(data.msg)
                            }
                            if(data.code==0){
                                $.modal.msgSuccess(data.msg)
                                var int=self.setInterval(function(){  // 这个方法是说在延迟两秒后执行大括号里的方法
                                    $.modal.reload();
                                },1000) //这里2000代表两秒

                            }
                            // $.modal.msgReload()
                        }
                });
            });
        }
        function goOut(id){
            $.modal.confirm("确认要通过吗?", function() {
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    url: prefix + "/goOut",
                    data: {
                        'id':id,
                    },
                    cache: false,
                    async: true,
                    success: function (data) {
                        $.modal.alertSuccess("通过成功");
                        $.table.refresh();
                    }
                });
            });
        }
        function refuse(id){
            $.modal.confirm("确认要拒绝吗?", function() {
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    url: prefix + "/refuse",
                    data: {
                        'id':id,
                    },
                    cache: false,
                    async: true,
                    success: function (data) {
                        $.modal.alertSuccess("拒绝成功");
                        $.table.refresh();
                    }
                });
            });
        }
        /*function look(id){
            // $.modal.confirm("确认要审核拒绝吗?", function() {
                alert("暂不可用");
            // });
        }*/

        $("#datetimepicker-demo-2").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function editAppointment(id){
            window.location.href=prefix+"/edit/"+id;
        }
    </script>
</body>
</html>